﻿using System;
using System.Linq;

namespace Tofu.Core
{

    public class BaseService<T> : IDisposable where T : class, new()
    {

        private static readonly Lazy<T> _instance = new Lazy<T>(() => new T());

        public static T Instance
        {
            get { return _instance.Value; }
        }

        public static int GetEntityAutoIncrement<T>(Func<T, int> expression, IQueryable<T> entity, int increment = 1) where T : class
        {
            return entity.Max(expression) + increment;
        }

        public void Dispose()
        {
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }

    }

}